/*
 * @Author: TJN tjn@246@126.com
 * @Date: 2024-07-15 14:01:44
 * @LastEditors: TJN tjn@246@126.com
 * @LastEditTime: 2024-07-16 16:37:52
 * @FilePath: \router\vite.config.ts
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */

import { ConfigEnv, defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import alias from "./vite/alias";
import { parseEnv } from "./vite/util";
import setupPlugins from "./vite/plugins/index.ts";
import { server } from "typescript";
// 处理环境变量
export default ({ command, mode }: ConfigEnv) => {
  console.log(command);
  console.log(mode);

  const isBuild = command === "build";

  // 配置文件目录
  const root = process.cwd();

  // 处理环境变量
  const env = parseEnv(loadEnv(mode, root));

  // 设置插件
  setupPlugins(isBuild, env);

  return {
    // plugins: [vue()],
    plugins: setupPlugins(isBuild, env),
    resolve: {
      alias,
    },
    server:{
      open:true,
      host:'0.0.0.0',
      proxy:{
        '/api':{
          target:'http://localhost:3000',
          changeOrigin:true,
          rewrite:(path:string)=>path.replace(/^\/api/,'')
        }
      }
    }
  };
};
